package org.tio.sitexxx.service.init;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.sitexxx.service.cache.CacheConfig;
import org.tio.sitexxx.service.cache.Caches;
import org.tio.utils.jfinal.P;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;

/**
 * @author tanyaowu
 * 2016年8月10日 下午1:43:50
 */
public class CacheInit {
	private static Logger log = LoggerFactory.getLogger(CacheInit.class);

	public static void init() {
		Caches.init();
		clearCache();
	}

	private static void clearCache() {
		boolean devFlag = P.getBoolean("clear.cache.flag", false);

		if (devFlag) {
			log.info("{}:系统启动时，进行了缓存清除操作.", DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN));
			Caches.getCache(CacheConfig.LOGINNAME_USER).clear();
			Caches.getCache(CacheConfig.USERID_USER).clear();
			Caches.getCache(CacheConfig.GROUP_CHAT_LOG).clear();
		}
	}
}
